﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.Xml;
using System.IO;

namespace Reborn_WorldServer.App1AppHandler
{
    public class RecipieItem
    {
        public Loot Item;

        public int Qty;
        public bool IsConsumed;

        virtual public void copyFrom(RecipieItem copyFromItem)
        {
            Item = copyFromItem.Item;
            Qty = copyFromItem.Qty;
            IsConsumed = copyFromItem.IsConsumed;
        }

        virtual public void writeXmlAttributes(XmlTextWriter xmldoc, Character sendingToCharacter)
        {
            xmldoc.WriteAttributeString("Qty", Qty.ToString());
            xmldoc.WriteAttributeString("IsConsumed", IsConsumed.ToString());
        }
        virtual public void writeXmlElements(XmlTextWriter xmldoc, Character sendingToCharacter)
        {
            xmldoc.WriteRaw(Item.toXML(sendingToCharacter));
        }

        public string toXml(Character sendingToCharacter)
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("recipieitem");

            writeXmlAttributes(xmldoc, sendingToCharacter);
            writeXmlElements(xmldoc, sendingToCharacter);

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
